package org.destinyshine.cricket.utils.compress;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

/**
 * Created by destinyliu on 2016/5/15.
 */
public abstract class ZipUtils {

    public static void extractAll(File file, String dir) throws IOException {
        ZipFile zipFile = new ZipFile(file);
        Enumeration<? extends ZipEntry> entries = zipFile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            File entryFile = new File(dir, entry.getName());
            if (!entry.isDirectory()) {
                InputStream is = zipFile.getInputStream(entry);
                FileUtils.copyInputStreamToFile(is, entryFile);
            }
        }

    }

}
